package com.blog.web.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blog.common.domain.entity.Page;
import com.blog.common.domain.vo.PageVo;
import com.blog.common.redis.service.RedisService;

import com.blog.common.mapper.dao.PageMapper;
import com.blog.web.service.PageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import static com.blog.common.core.constant.CacheConstants.*;

/**
 * <p>
 * 页面 服务实现类
 * </p>
 *
 * @author Valerie
 * @since 2023-02-18
 */
@Service
public class PageServiceImpl extends ServiceImpl<PageMapper, Page> implements PageService {

    @Resource
    private RedisService redisService;


    @Override
    public List<PageVo> listPages() {

        List<PageVo> list;
        if (!redisService.exists(PAGE_COVER)){
            list = BeanUtil.copyToList(this.list(), PageVo.class);
            redisService.set(PAGE_COVER, list);
        }
        else {
            list = (List<PageVo>) redisService.get(PAGE_COVER);
        }
        return list;
    }
}
